<?php
/**
* 文件名(index.con.php)
*
* 功能描述（主页控制器）
*
* @author suoya <jlusuoya@gmail.com>
* @version 1
*/
/*
update
V10－jlusuoya－20130827: 创建
update
*/
require('../smarty-3.1.13/Smarty.class.php');
require_once(MODEL_DIR . "userbase.php");

class CtrlBase extends Smarty
{
	public $user = null;
	public $params = array();
	public $paramCheck = array();
	public $search = array();		//搜索关键字
	public $page = array('cur'=>1, 'size'=>0, 'cnt' => 0, 'pageCnt' => 0);
	public $perm = array('none', "index.php?action=login.tologin");	//默认无权限

	function __construct()
	{
		parent::__construct();
		$this->debugging = DEBUG;
		$this->caching = false;
		$this->cache_lifetime = 120;
		$this->left_delimiter = "{#";
		$this->right_delimiter = "#}";
		$this->template_dir = SRV_BASE . "templates/";
		$this->compile_dir = SRV_BASE . "templates_c/";
		$this->config_dir = SRV_BASE . "configs/";
		$this->cache_dir = SRV_BASE . "cache/";
		if(DEBUG)
			$this->force_compile = true;
		else
			$this->compile_check = true;
		//global var
		$this->LoadInfo();
		global $web_root;
		$this->assign("web_root", $web_root);
		if(array_key_exists("g_ext", $_GET))
			$this->assign("g_ext", $_GET['g_ext']);
	}

	function LoadInfo()
	{
		//user
		$this->user = new UserBase();
		if($this->user->logined)
		{
			$this->assign("username", $this->user->username);
			$this->assign("truename", $this->user->truename);
			$this->assign("mobile", $this->user->mobile);
			$this->assign("perms", $this->user->perms);
		}
		else
			$this->ClearAssign(array("username", "truename", "mobile"));
	}

	function GetModel($name)
	{
		$name = strtolower($name);
		require_once(MODEL_DIR . "$name.mod.php");
		$model = "Model" . $name;
		return new $model();
	}

	function GetCtrl($name)
	{
		$name = strtolower($name);
		require_once(CTRL_DIR . "$name.con.php");
		$ctrl = "Ctrl" . $name;
		return new $ctrl();
	}

	function CheckPermissions($method)
	{
		$group = $this->perm[0];
		if($this->user->perms[$group] == 0)
		{
			if($this->user->logined)
				$msg = '权限不足';
			else
				$msg = '';
			jump_to($this->perm[1], $msg);
		}
	}

	function CoreLog($type, $dataid, $param, $desp)
	{
		global $g_log_types;
		$obj = $this->GetModel("log");
		$obj->NewLog($this->user->userid, $g_log_types[$type], $dataid, $param, $desp);
	}
}

